package com.yiji.fintech.musfinance.base.enums;

import com.acooly.core.utils.enums.Messageable;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 交易类型
 *
 * @author ouwen
 * 
 */
public enum TradeTypeEnum implements Messageable {
	SIGN("SIGN","签约"),
	DEDUCT_DEPOSIT("DEDUCT_DEPOSIT", "代扣充值"),
	NET_DEPOSIT("NET_FORM_DEPOSIT", "网银表单充值"),
	OFFLINE_PAY("OFFLINE_PAY", "线下打款"),
	WITHDRAW("WITHDRAW", "提现"),
	DEPOSIT_BACK("DEPOSIT_BACK", "充值充退"),
	WECHAT_PUBLIC_PAY("WECHAT_PUBLIC_PAY", "微信公众号支付"),
	WECHAT_APP_PAY("WECHAT_APP_PAY", "微信APP支付"),
	// 被扫
	WECHAT_SCAN_CODEED_PAY("WECHAT_SCAN_CODEED_PAY", "微信反扫支付"),
	// 主扫
	WECHAT_SCAN_CODE_PAY("WECHAT_SCAN_CODE_PAY", "微信扫码支付"),
	ALI_APP_PAY("ALI_APP_PAY", "支付宝APP支付"),
	ALI_APP_PAGE_PAY("ALI_APP_PAGE_PAY", "支付宝H5支付"),
	ALI_PC_PAGE_PAY("ALI_PC_PAGE_PAY", "支付宝PC页面支付"),
	// 被扫
	ALI_SCAN_CODEED_PAY("ALI_SCAN_CODEED_PAY", "支付宝反扫支付"),
	// 主扫
	ALI_SCAN_CODE_PAY("ALI_SCAN_CODE_PAY", "支付宝扫码支付"),
	NET_DEPOSIT_PAY_BACK("NET_DEPOSIT_PAY_BACK", "网银充退"),
	SERVICE_WINDOW("SERVICE_WINDOW","支付服务窗"),
	ASYNC_NOTIFY("ASYNC_NOTIFY","异步通知");

	private final String code;
	private final String message;

	private TradeTypeEnum(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	@Override
    public String code() {
		return code;
	}

	@Override
    public String message() {
		return message;
	}

	public static Map<String, String> mapping() {
		Map<String, String> map = new LinkedHashMap<String, String>();
		for (TradeTypeEnum type : values()) {
			map.put(type.getCode(), type.getMessage());
		}
		return map;
	}

	/**
	 * 通过枚举值码查找枚举值。
	 * 
	 * @param code
	 *            查找枚举值的枚举值码。
	 * @return 枚举值码对应的枚举值。
	 * @throws IllegalArgumentException
	 *             如果 code 没有对应的 Status 。
	 */
	public static TradeTypeEnum find(String code) {
		for (TradeTypeEnum status : values()) {
			if (status.getCode().equals(code)) {
				return status;
			}
		}
		throw new IllegalArgumentException("Type not legal:" + code);
	}

	/**
	 * 获取全部枚举值。
	 * 
	 * @return 全部枚举值。
	 */
	public static List<TradeTypeEnum> getAll() {
		List<TradeTypeEnum> list = new ArrayList<TradeTypeEnum>();
		for (TradeTypeEnum status : values()) {
			list.add(status);
		}
		return list;
	}

	/**
	 * 获取全部枚举值码。
	 * 
	 * @return 全部枚举值码。
	 */
	public static List<String> getAllCode() {
		List<String> list = new ArrayList<String>();
		for (TradeTypeEnum status : values()) {
			list.add(status.code());
		}
		return list;
	}

	@Override
	public String toString() {
		return String.format("%s:%s", this.code, this.message);
	}

}
